import cluster from 'cluster';
import { start } from './server';

if (cluster.isMaster) {
    const numCPUs = 1;

    // fork workers
    let i = 0;
    for (i = 0; i < numCPUs; i++) {
        cluster.fork();
    }

    cluster.on('online', (worker) => {
        console.log('worker %d is online.', worker.process.pid);
    });

    cluster.on('exit', (worker) => {
        console.log('worker %d is died.', worker.process.pid);
        console.log('starting a new worker');
        cluster.fork();
    });
} else {
    // start server
    start();
}
